#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
vector<ll> ans(100);
vector<ll> vis(100);
ll n;
void dfs(ll dep)
{
    if(dep>=n)
    {
        for (ll i = 0; i < n;i++)
        {
            cout << ans[i] << " ";
        }
        cout << "\n";
    }

    for (ll i = 1; i <= n;i++)
    {
        if(vis[i])
            continue;
        vis[i] = 1;
        ans[dep] = i;
        dfs(dep + 1);
       // ans[dep]=0;
        vis[i] = 0;
    }
}
void solve()
{
 
    cin >> n;
    dfs(0);
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
